home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / vol16n13.zip / ATLCTL.ZIP / AtlEditCtl.cpp < prev    next >
C/C++ Source or Header  |  1997-01-28  |  2KB  |  67 lines

  1. // AtlEditCtl.cpp : Implementation of CAtlEditCtl
  2. #include "stdafx.h"
  3. #include "AtlEdit10.h"
  4. #include "AtlEditCtl.h"
  5.  
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CAtlEditCtl
  8.  
  9.  
  10. HRESULT CAtlEditCtl::OnDraw(ATL_DRAWINFO& di)
  11. {
  12.     USES_CONVERSION;
  13.  
  14.     HDC hdc = di.hdcDraw;
  15.     HDC hic = di.hicTargetDev;
  16.     RECT& rc = *(RECT*)( di.prcBounds );
  17.  
  18.     if( hic == NULL )
  19.         hic = AtlCreateTargetDC( hdc, di.ptd );
  20.  
  21.     if( di.dwDrawAspect != DVASPECT_CONTENT )
  22.         return 0;
  23.  
  24.     HPEN hFore;
  25.     HBRUSH hBack;
  26.     COLORREF colBack, colFore;
  27.  
  28.     OleTranslateColor( m_clrBackColor, m_hPalette, &colBack );
  29.     OleTranslateColor( m_clrForeColor, m_hPalette, &colFore );
  30.  
  31.     hBack = CreateSolidBrush( colBack );
  32.     hFore = CreatePen( PS_SOLID, 2, colFore );
  33.  
  34.     HGDIOBJ hOldBrush = SelectObject( hdc, hBack );
  35.     HGDIOBJ hOldPen = SelectObject( hdc, hFore );
  36.  
  37.     FillRect( hdc, &rc, hBack );
  38.     DrawEdge( hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST );
  39.  
  40.     // Draw our text to the control
  41.  
  42.     if( m_Font != NULL )
  43.     {
  44.         HFONT hFont, hOldFont;
  45.         m_Font->get_hFont( &hFont );
  46.         hOldFont = (HFONT) SelectObject( hdc, hFont );
  47.         
  48.         SetTextColor( hdc, colFore );
  49.         SetBkMode( hdc, TRANSPARENT );
  50.  
  51.         TextOut( hdc, rc.left, rc.top, OLE2T( m_bstrText ), m_bstrText.Length() );
  52.  
  53.         if( hOldFont )
  54.             SelectObject( hdc, hOldFont );
  55.     }
  56.  
  57.     SelectObject( hdc, hOldBrush );
  58.     SelectObject( hdc, hOldPen );
  59.  
  60.     DeleteObject( reinterpret_cast< HGDIOBJ >( hBack ) );
  61.  
  62.     if( hic != hdc )
  63.         DeleteDC( hic );
  64.  
  65.     return S_OK;
  66. }
  67.